package util;

import io.GeneFileReader;

public class Extractor {
	private GeneFileReader m_reader;

	public Extractor(GeneFileReader reader) {
		m_reader = reader;
	}

	public void extract() {
		Gene gene1, gene2;
		int x = 0;
		String num="16";
		for (int i = 0; i < m_reader.numberOfGenes() - 1; i++) {
			gene1 = new Gene(m_reader.getAnnotationAt(i), m_reader.getGeneAt(i));
			for (int j = i + 1; j < m_reader.numberOfGenes(); j++) {
				gene2 = new Gene(m_reader.getAnnotationAt(j), m_reader
						.getGeneAt(j));
				if (gene1.overlap(gene2)) {
					
					long[] ans = gene1.overlapCoordinates(gene2);
					if (ans[1] - ans[0] >= 21) {
						x++;
						//System.out.println(ans[0] + " " + ans[1]);

						if (gene1.getDirection() == 1) {
							System.out.println(">"+num+"_sequence_"+x+"\n"+
									 gene1.getSequenceNotComplementary(ans[0],
											ans[1]));
							System.out.println(">"+num+"_complementary_sequence_"+x+"\n"+
									 gene1.getComplementarySequence(gene1
											.getSequenceNotComplementary(
													ans[0], ans[1])));
						} else {
							System.out.println(">"+num+"_sequence_"+x+"\n"
									+ gene2.getSequenceNotComplementary(ans[0],
											ans[1]));
							System.out.println(">"+num+"_complementary_sequence_"+x+"\n"
									+ gene2.getComplementarySequence(gene2
											.getSequenceNotComplementary(
													ans[0], ans[1])));
						}
					}
				}
			}
		}
		System.out.println("num of overlaps:" + x);
	}
}
